Show a map
basemap %>%
# Home - Black
# Friends - Red
# Business - Blue
# Visit - Orange
addPolygons(data=hom, color = "black",
weight = 1, fillOpacity = 0.3,
group = "Home",
popup = paste("<p>", hom@data$COUNTRY,"<p>")) %>%
addPolygons(data=biz, color = "blue",
weight = 1, fillOpacity = 0.3,
group = "Business",
popup = paste("<p>", biz@data$COUNTRY,"<p>")) %>%
addPolygons(data=vis, color = "orange",
weight = 1, fillOpacity = 0.3,
group = "Visited",
popup = paste("<p>", vis@data$COUNTRY,"<p>")) %>%
addPolygons(data=fri, color = "red",
weight = 1, fillOpacity = 0.3,
group = "Friends",
popup = paste("<p>", fri@data$COUNTRY,"<p>")) %>%
addLayersControl(overlayGroups = c("Friends","Visited","Business"))
# Loading World data
world <- map_data("world")
world$region %>%
unique()
## [1] "Aruba"
## [2] "Afghanistan"
## [3] "Angola"
## [4] "Anguilla"
## [5] "Albania"
## [6] "Finland"
## [7] "Andorra"
## [8] "United Arab Emirates"
## [9] "Argentina"
## [10] "Armenia"
## [11] "American Samoa"
## [12] "Antarctica"
## [13] "Australia"
## [14] "French Southern and Antarctic Lands"
## [15] "Antigua"
## [16] "Barbuda"
## [17] "Austria"
## [18] "Azerbaijan"
## [19] "Burundi"
## [20] "Belgium"
## [21] "Benin"
## [22] "Burkina Faso"
## [23] "Bangladesh"
## [24] "Bulgaria"
## [25] "Bahrain"
## [26] "Bahamas"
## [27] "Bosnia and Herzegovina"
## [28] "Saint Barthelemy"
## [29] "Belarus"
## [30] "Belize"
## [31] "Bermuda"
## [32] "Bolivia"
## [33] "Brazil"
## [34] "Barbados"
## [35] "Brunei"
## [36] "Bhutan"
## [37] "Botswana"
## [38] "Central African Republic"
## [39] "Canada"
## [40] "Switzerland"
## [41] "Chile"
## [42] "China"
## [43] "Ivory Coast"
## [44] "Cameroon"
## [45] "Democratic Republic of the Congo"
## [46] "Republic of Congo"
## [47] "Cook Islands"
## [48] "Colombia"
## [49] "Comoros"
## [50] "Cape Verde"
## [51] "Costa Rica"
## [52] "Cuba"
## [53] "Curacao"
## [54] "Cayman Islands"
## [55] "Cyprus"
## [56] "Czech Republic"
## [57] "Germany"
## [58] "Djibouti"
## [59] "Dominica"
## [60] "Denmark"
## [61] "Dominican Republic"
## [62] "Algeria"
## [63] "Ecuador"
## [64] "Egypt"
## [65] "Eritrea"
## [66] "Canary Islands"
## [67] "Spain"
## [68] "Estonia"
## [69] "Ethiopia"
## [70] "Fiji"
## [71] "Falkland Islands"
## [72] "Reunion"
## [73] "Mayotte"
## [74] "French Guiana"
## [75] "Martinique"
## [76] "Guadeloupe"
## [77] "France"
## [78] "Faroe Islands"
## [79] "Micronesia"
## [80] "Gabon"
## [81] "UK"
## [82] "Georgia"
## [83] "Guernsey"
## [84] "Ghana"
## [85] "Guinea"
## [86] "Gambia"
## [87] "Guinea-Bissau"
## [88] "Equatorial Guinea"
## [89] "Greece"
## [90] "Grenada"
## [91] "Greenland"
## [92] "Guatemala"
## [93] "Guam"
## [94] "Guyana"
## [95] "Heard Island"
## [96] "Honduras"
## [97] "Croatia"
## [98] "Haiti"
## [99] "Hungary"
## [100] "Indonesia"
## [101] "Isle of Man"
## [102] "India"
## [103] "Cocos Islands"
## [104] "Christmas Island"
## [105] "Chagos Archipelago"
## [106] "Ireland"
## [107] "Iran"
## [108] "Iraq"
## [109] "Iceland"
## [110] "Israel"
## [111] "Italy"
## [112] "San Marino"
## [113] "Jamaica"
## [114] "Jersey"
## [115] "Jordan"
## [116] "Japan"
## [117] "Siachen Glacier"
## [118] "Kazakhstan"
## [119] "Kenya"
## [120] "Kyrgyzstan"
## [121] "Cambodia"
## [122] "Kiribati"
## [123] "Nevis"
## [124] "Saint Kitts"
## [125] "South Korea"
## [126] "Kosovo"
## [127] "Kuwait"
## [128] "Laos"
## [129] "Lebanon"
## [130] "Liberia"
## [131] "Libya"
## [132] "Saint Lucia"
## [133] "Liechtenstein"
## [134] "Sri Lanka"
## [135] "Lesotho"
## [136] "Lithuania"
## [137] "Luxembourg"
## [138] "Latvia"
## [139] "Saint Martin"
## [140] "Morocco"
## [141] "Monaco"
## [142] "Moldova"
## [143] "Madagascar"
## [144] "Maldives"
## [145] "Mexico"
## [146] "Marshall Islands"
## [147] "North Macedonia"
## [148] "Mali"
## [149] "Malta"
## [150] "Myanmar"
## [151] "Montenegro"
## [152] "Mongolia"
## [153] "Northern Mariana Islands"
## [154] "Mozambique"
## [155] "Mauritania"
## [156] "Montserrat"
## [157] "Mauritius"
## [158] "Malawi"
## [159] "Malaysia"
## [160] "Namibia"
## [161] "New Caledonia"
## [162] "Niger"
## [163] "Norfolk Island"
## [164] "Nigeria"
## [165] "Nicaragua"
## [166] "Niue"
## [167] "Bonaire"
## [168] "Sint Eustatius"
## [169] "Saba"
## [170] "Netherlands"
## [171] "Norway"
## [172] "Nepal"
## [173] "Nauru"
## [174] "New Zealand"
## [175] "Oman"
## [176] "Pakistan"
## [177] "Panama"
## [178] "Pitcairn Islands"
## [179] "Peru"
## [180] "Philippines"
## [181] "Palau"
## [182] "Papua New Guinea"
## [183] "Poland"
## [184] "Puerto Rico"
## [185] "North Korea"
## [186] "Madeira Islands"
## [187] "Azores"
## [188] "Portugal"
## [189] "Paraguay"
## [190] "Palestine"
## [191] "French Polynesia"
## [192] "Qatar"
## [193] "Romania"
## [194] "Russia"
## [195] "Rwanda"
## [196] "Western Sahara"
## [197] "Saudi Arabia"
## [198] "Sudan"
## [199] "South Sudan"
## [200] "Senegal"
## [201] "Singapore"
## [202] "South Sandwich Islands"
## [203] "South Georgia"
## [204] "Saint Helena"
## [205] "Ascension Island"
## [206] "Solomon Islands"
## [207] "Sierra Leone"
## [208] "El Salvador"
## [209] "Somalia"
## [210] "Saint Pierre and Miquelon"
## [211] "Serbia"
## [212] "Sao Tome and Principe"
## [213] "Suriname"
## [214] "Slovakia"
## [215] "Slovenia"
## [216] "Sweden"
## [217] "Swaziland"
## [218] "Sint Maarten"
## [219] "Seychelles"
## [220] "Syria"
## [221] "Turks and Caicos Islands"
## [222] "Chad"
## [223] "Togo"
## [224] "Thailand"
## [225] "Tajikistan"
## [226] "Turkmenistan"
## [227] "Timor-Leste"
## [228] "Tonga"
## [229] "Trinidad"
## [230] "Tobago"
## [231] "Tunisia"
## [232] "Turkey"
## [233] "Taiwan"
## [234] "Tanzania"
## [235] "Uganda"
## [236] "Ukraine"
## [237] "Uruguay"
## [238] "USA"
## [239] "Uzbekistan"
## [240] "Vatican"
## [241] "Grenadines"
## [242] "Saint Vincent"
## [243] "Venezuela"
## [244] "Virgin Islands"
## [245] "Vietnam"
## [246] "Vanuatu"
## [247] "Wallis and Futuna"
## [248] "Samoa"
## [249] "Yemen"
## [250] "South Africa"
## [251] "Zambia"
## [252] "Zimbabwe"
biz_country <- c("Australia","Bangladesh","Burkina Faso",
"Chile","Cyprus","China","Germany","Egypt","France",
"UK","India","Israel","Italy","Kenya","Cambodia","South Korea",
"Sri Lanka","Mongolia","Poland","Russia","Singapore","USA")
vis_country <- c("Australia","Belgium","Brunei","Canada","France",
"Guam","India","Italy","Kenya","Cambodia","South Korea",
"Mexico","Netherlands","New Zealand","Philippines","Singapore",
"Thailand","Taiwan","USA","Vietnam")
fri_country <- c("Afghanistan","Albania","Australia","Brazil","Brunei",
"Canada","Colombia","Cape Verde","China","Denmark","Spain",
"France","India","Italy","Kenya",
"South Korea","Saudi Arabia","Mexico","Myanmar",
"Pakistan","Peru","Philippines","Puerto Rico",
"North Korea","El Salvador","Thailand","Taiwan","Uganda",
"USA","United Arab Emirates","Vietnam")
# Remove the Antarctica region
world <- subset(world, region != "Antarctica")
# Remove the French Southern and Antarctic Lands region
world <- subset(world, region != "French Southern and Antarctic Lands")
world$cat <- NA
world$cat[world$region %in% biz_country] <- "biz"
world$cat[world$region %in% fri_country] <- "fri"
world$cat[world$region %in% vis_country] <- "vis"
world$cat[world$region %in% c("Japan")] <- "hom"
world$cat <- replace_na(world$cat,'NA')
world$cat <- factor(world$cat, levels = c("biz","fri","vis","hom","NA"))
Show a map
# plot
ggplot(data = world, aes(x = long, y = lat, group = group)) +
geom_polygon(fill = "white", color = "black", size = 0.3) +
geom_polygon(aes(fill = cat),size = 0.3, alpha = 0.3) +
scale_fill_manual(values=c("blue","red","yellow","black","white"),name = "Country", labels = c("Business", "Friends", "Visited","Home", "NA")) +
#Add a theme to your final map
theme_void() +
theme(legend.position = "bottom") +
# Add titles to your axis (optional)
xlab("") +
ylab("") +
# Choose the size of your map
coord_fixed(ratio=1.5, xlim = c(-165,175), ylim = c(-50,78))